﻿using TextExtractionMaster.Extractor;

namespace TextExtractionMaster
{
    public class TextExtractionTool
    {
        private readonly Dictionary<string, ITextExtractor> extractors;

        public TextExtractionTool()
        {
            extractors = new Dictionary<string, ITextExtractor>
        {
            { ".docx", new WordDocxTextExtractor() },
            { ".doc", new WordDocTextExtractor() },
            { ".pdf", new PdfTextExtractor() },
            { ".png", new ImageTextExtractor() },
            { ".jpg", new ImageTextExtractor() },
            { ".gif", new ImageTextExtractor() },
            { ".bmp", new ImageTextExtractor() }
        };
        }

        public string ExtractText(string filePath)
        {
            var extension = Path.GetExtension(filePath).ToLower();
            if (extractors.ContainsKey(extension))
            {
                ITextExtractor extractor = extractors[extension];
                return extractor.ExtractText(filePath);
            }
            else
            {
                throw new NotSupportedException($"File type {extension} is not supported.");
            }
        }
    }
}
